﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Mang
{
    public class BubbleSort<T> : ThuatToanSapXep<T> where T : IComparable
    {
        //Sap Xep tang dan
        public override void SapXep(T[] a, int n)
        {
            for (int i = 0; i < n - 1; i++)
            {
                for (int j = n - 2; j >= i; j--)
                {
                    if (a[j].CompareTo(a[j+1]) > 0)////////????????
                    {
                        HoanVi(ref a[j], ref a[j+1]);
                    }
                }
            }
        }

        //Sap Xep tang dan
        public override void SapXep(T[] a, int n, TieuChiSapXep<T> tc)
        {
            for (int i = 0; i < n - 1; i++)
            {
                for (int j = n - 2; j >= i; j--)
                {
                    if(tc.Compare(a[j], a[j+1]) > 0)//if (a[j].CompareTo(a[j + 1]) > 0)////////????????
                    {
                        HoanVi(ref a[j], ref a[j+1]);
                    }
                }
            }
        }
    }
}
